package test.demo;

import com.alibaba.fastjson.JSON;
import tech.waterism.modelbase.PredictBase;
import tech.waterism.modelbase.PredictResult;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 初损后损法 超渗产流
 *
 * @author 初京刚
 * @version 1.0
 * @date 2023-7-18
 */

public class ITCA extends PredictBase {

    /**
     * 初始有效饱和度
     */
    private double Se0;

    /**
     * 雨强 mm/min
     */
    private double PI;

    /**
     * 雨强整体下限 mm/min
     */
    private double PILE;

    /**
     * 雨强饱和度下限 mm/min
     */
    private double PILS;

    /**
     * 下限设置标记
     */
    private int flagL;

    /**
     * 初损期结束标记
     */
    private int flagIAE;

    /**
     * 初始有效饱和度下限
     */
    private double SeL;

    /**
     * 降水量
     */
    private double[] floodDrp;

    /**
     * 降水时间
     */
    private Date[] floodTm;

    /**
     * I~Ia/fc曲线条数
     */
    private int n;

    /**
     * 每条I～Ia/fc曲线对应的Se值
     */
    private double[] Se;

    /**
     * I～Ia/fc曲线节点对应的I值
     */
    private double[] I;

    /**
     * I～Ia/fc曲线的节点数
     */
    private int m;

    /**
     * I～Ia曲线
     */
    private double[][] Ii;
    private double[][] Ii_t;

    /**
     * I～fc曲线
     */
    private double[][] If;
    private double[][] If_t;

    /**
     * 降水序列长度
     */
    private Integer floodRainRange;

    /**
     * 降水时段长
     */
    private double timeInterval;

    /**
     * 模拟总产流
     */
    private double[] RunoffSim;

    /**
     * 总产流
     */
    private double[] R;

    /**
     * 初损值校正系数
     */
    private double IaF;

    /**
     * 平均后损率校正系数
     */
    private double FcF;

    public ITCA(Map<String, String> data) {
        super();
        Se0 = Double.parseDouble(data.get("SE0"));                             // 初始有效饱和度
        Se = JSON.parseObject(data.get("SE"), double[].class);                 // 每条PI～Ia/fc曲线对应的Se值
        if (Se != null) {
            n = Se.length;                                                     // I~Ia/fc曲线条数
        }
        I = JSON.parseObject(data.get("I"), double[].class);                   // I～Ia/fc曲线节点对应的I值
        if (I != null) {
            m = I.length;                                                      // I～Ia/fc曲线的节点数
        }
        Ii = JSON.parseObject(data.get("IA"), double[][].class);               // I～Ia曲线
        Ii_t = transpose(Ii);
        If = JSON.parseObject(data.get("FE"), double[][].class);               // I～fc曲线
        If_t = transpose(If);
        floodTm = JSON.parseObject(data.get("dt"), Date[].class);              // input[i].data.dt
        floodDrp = JSON.parseObject(data.get("rain"), double[].class);         // input[i].data.rain
        floodRainRange = floodDrp.length;
        if (floodTm.length > 1) {
            timeInterval = getHours(floodTm[0], floodTm[1]);
        } else {
            timeInterval = Double.parseDouble(data.get("clen"));                  // index.clen
        }

        if(data.get("I0") == null) {
            double pSum = 0.0;
            int count = 0;
            for (int i = 0; i < floodRainRange; i++) {
                if(floodDrp[i] > 0){
                    pSum += floodDrp[i];
                    count += 1;
                }
            }
            PI = pSum / (count * timeInterval * 60);
        } else {
            PI = Double.parseDouble(data.get("I0"));
        }


        RunoffSim = new double[floodRainRange];
        R = new double[floodRainRange];
        IaF = Double.parseDouble(data.get("IAF"));
        FcF = Double.parseDouble(data.get("FEF"));

        flagL = 0;
        for (int i = m - 1; i >= 0; i--) {
            for (int j = n - 1; j >= 0; j--) {
                if (Ii[i][j] == -9999 && If[i][j] == -9999) {
                    if (j == n - 1) {
                        PILE = I[i + 1];
                    } else {
                        PILE = I[i];
                        PILS = I[i + 1];
                        SeL = Se[j + 1];
                    }
                    flagL = 1;
                    break;
                }
            }
            if (flagL == 1) {
                break;
            }
        }
    }

    /**
     * 模型计算
     */
    public Map<String, double[]> ITCAModel() {

        //I～Ia/fc曲线计算
        if ((PI < PILE) || ((PI < PILS) && (Se0 < SeL))) {
            for (int i = 0; i < floodRainRange; i++) {
                RunoffSim[i] = 0.0;
                R[i] = 0.0;
            }
        } else {
            IIf();
        }

        Map<String, double[]> simulationResult = new HashMap<>();

        simulationResult.put("rain", floodDrp);
        simulationResult.put("runoffSim", RunoffSim);
        return simulationResult;
    }

    private int getHours(Date dt_beg, Date dt_end) {
        int hours = -1;
        hours = Long.valueOf((dt_end.getTime() - dt_beg.getTime()) / (3600 * 1000L)).intValue();
        return hours;
    }

    /**
     * I～Ia/fc曲线计算
     *
     * @return 产流
     */
    private void IIf() {
        double sumR1 = 0, sumR2 = 0, sumP1 = 0, sumP2 = 0;
        double Ia, fc;

        int j_se = 0; //标记Pa插值点
        int j_se_1; //Se下限
        int j_se_2; //Se上限
        int j_se_mark = 0;// 标记是否插值
        if (Se0 > Se[n - 1]) {
            j_se = n - 1;
            j_se_mark = 1; //不用插值
        } else {
            for (int j = n - 1; j >= 0; j--) {
                if (Math.abs(Se0 - Se[j]) < 0.0001) { //几乎相等
                    j_se = j;
                    j_se_mark = 1; //不用差值
                } else if (Se0 < Se[j]) {
                    j_se = j - 1;
                    if (j_se < 0) {
                        j_se = 0;
                    }
                }
            }
        }
        if (j_se == 0) {
            if (Se0 < Se[j_se]) {
                j_se_1 = j_se;
                j_se_2 = j_se;
            } else {
                j_se_1 = j_se;
                j_se_2 = j_se + 1;
            }
        } else if (j_se == n - 1) {
            j_se_1 = j_se;
            j_se_2 = j_se;
        } else {
            j_se_1 = j_se;
            j_se_2 = j_se + 1;
        }

        if (j_se_mark != 1) {
            if (j_se_1 == j_se_2) {
                Ia = calculateIF(PI, I, Ii_t[j_se_1], m) * IaF;
                fc = calculateIF(PI, I, If_t[j_se_1], m) * FcF;
            } else {
                double temp1 = calculateIF(PI, I, Ii_t[j_se_1], m);
                double temp2 = calculateIF(PI, I, Ii_t[j_se_2], m);
                Ia = (temp2 * (Se0 - Se[j_se_1]) + temp1 * (Se[j_se_2] - Se0)) / (Se[j_se_2] - Se[j_se_1]) * IaF;

                temp1 = calculateIF(PI, I, If_t[j_se_1], m);
                temp2 = calculateIF(PI, I, If_t[j_se_2], m);
                fc = (temp2 * (Se0 - Se[j_se_1]) + temp1 * (Se[j_se_2] - Se0)) / (Se[j_se_2] - Se[j_se_1]) * FcF;
            }
        } else {
            Ia = calculateIF(PI, I, Ii_t[j_se_1], m) * IaF;
            fc = calculateIF(PI, I, If_t[j_se_1], m) * FcF;
        }

        flagIAE = 0;
        for (int i = 0; i < floodRainRange; i++) {
            sumP1 += floodDrp[i];
            if (flagIAE == 0) {
                if (sumP1 < Ia) {
                    RunoffSim[i] = 0.0;
                    R[i] = RunoffSim[i];
                } else {
                    if (floodDrp[i] / (timeInterval * 60) > fc) {
                        RunoffSim[i] =
                                (sumP1 - Ia) - fc * ((sumP1 - Ia) / (floodDrp[i] / (timeInterval * 60)));
                    } else {
                        RunoffSim[i] = 0.0;
                    }
                    R[i] = RunoffSim[i];
                    flagIAE = 1;
                }
            } else {
                if (floodDrp[i] / (timeInterval * 60) > fc) {
                    RunoffSim[i] = floodDrp[i] - fc * timeInterval * 60;
                } else {
                    RunoffSim[i] = 0.0;
                }
                R[i] = RunoffSim[i];
            }
        }
    }

    /**
     * 插值计算径流量
     *
     * @param P    降雨强度
     * @param I    I～Ia/fc曲线降雨强度序列
     * @param IF   I～Ia/fc曲线Ia/fc序列
     * @param i_if I～Ia/fc曲线降雨序列长度
     * @return 一个与降雨强度对应的Ia/fc
     */
    private double calculateIF(double P, double[] I, double[] IF, int i_if) {
        double IIF = insert2(P, I, IF, i_if);
        return IIF;
    }

    /**
     * 插值计算
     */
    public double insert2(double x0, double x[], double y[], int n) { // 两点插值(float)
        if (n <= 1) {
            return 0;
        }
        int i;
        double y0, x1, x2;
        if (x[0] < x[n - 1]) { // *x[] is ascending
            for (i = 0; i < n; i++) {
                if (x0 <= x[i]) {
                    break;
                }
            }
        } else { // *x[] is descending
            for (i = 0; i < n; i++) {
                if (x0 >= x[i]) {
                    break;
                }
            }
        }
        if (i >= n - 1) {
            i = n - 2;
        } else if (i <= 1) {
            i = 0;
        } else {
            i--;
        }
        x1 = x[i];
        x2 = x[i + 1];

        if (x1 == x2) {
            return y[i];
        }
        y0 = y[i] + (x0 - x1) / (x2 - x1) * (y[i + 1] - y[i]);

        return y0;
    }

    public static double[][] transpose(double[][] A) {
        int R = A.length, C = A[0].length;
        double[][] ans = new double[C][R];
        for (int r = 0; r < R; r++)
            for (int c = 0; c < C; c++)
                ans[c][r] = A[r][c];
                return ans;
    }

    @Override
    public void init() {
    }

    @Override
    public PredictResult predict() {
        PredictResult result = new PredictResult();
        Map<String, double[]> map = ITCAModel();
        double[][] RSim = new double[1][];
        RSim[0] = map.get("runoffSim");

        result.setRunoffSim(map.get("runoffSim"));
        result.setRSim(RSim);

        return result;
    }

    public static void main(String[] args) {
        String a = "{\"dt\":\"[\\\"2013-05-02 08:00:00\\\",\\\"2013-05-02 14:00:00\\\",\\\"2013-05-02 20:00:00\\\",\\\"2013-05-03 02:00:00\\\",\\\"2013-05-03 08:00:00\\\",\\\"2013-05-03 14:00:00\\\",\\\"2013-05-03 20:00:00\\\",\\\"2013-05-04 02:00:00\\\",\\\"2013-05-04 08:00:00\\\",\\\"2013-05-04 14:00:00\\\",\\\"2013-05-04 20:00:00\\\",\\\"2013-05-05 02:00:00\\\",\\\"2013-05-05 08:00:00\\\",\\\"2013-05-05 14:00:00\\\",\\\"2013-05-05 20:00:00\\\",\\\"2013-05-06 02:00:00\\\",\\\"2013-05-06 08:00:00\\\",\\\"2013-05-06 14:00:00\\\",\\\"2013-05-06 20:00:00\\\",\\\"2013-05-07 02:00:00\\\",\\\"2013-05-07 08:00:00\\\",\\\"2013-05-07 14:00:00\\\",\\\"2013-05-07 20:00:00\\\",\\\"2013-05-08 02:00:00\\\",\\\"2013-05-08 08:00:00\\\",\\\"2013-05-08 14:00:00\\\",\\\"2013-05-08 20:00:00\\\",\\\"2013-05-09 02:00:00\\\",\\\"2013-05-09 08:00:00\\\",\\\"2013-05-09 14:00:00\\\",\\\"2013-05-09 20:00:00\\\",\\\"2013-05-10 02:00:00\\\",\\\"2013-05-10 08:00:00\\\",\\\"2013-05-10 14:00:00\\\",\\\"2013-05-10 20:00:00\\\",\\\"2013-05-11 02:00:00\\\",\\\"2013-05-11 08:00:00\\\",\\\"2013-05-11 14:00:00\\\",\\\"2013-05-11 20:00:00\\\",\\\"2013-05-12 02:00:00\\\",\\\"2013-05-12 08:00:00\\\",\\\"2013-05-12 14:00:00\\\",\\\"2013-05-12 20:00:00\\\",\\\"2013-05-13 02:00:00\\\",\\\"2013-05-13 08:00:00\\\",\\\"2013-05-13 14:00:00\\\",\\\"2013-05-13 20:00:00\\\",\\\"2013-05-14 02:00:00\\\",\\\"2013-05-14 08:00:00\\\",\\\"2013-05-14 14:00:00\\\",\\\"2013-05-14 20:00:00\\\",\\\"2013-05-15 02:00:00\\\",\\\"2013-05-15 08:00:00\\\",\\\"2013-05-15 14:00:00\\\",\\\"2013-05-15 20:00:00\\\",\\\"2013-05-16 02:00:00\\\",\\\"2013-05-16 08:00:00\\\",\\\"2013-05-16 14:00:00\\\",\\\"2013-05-16 20:00:00\\\",\\\"2013-05-17 02:00:00\\\",\\\"2013-05-17 08:00:00\\\",\\\"2013-05-17 14:00:00\\\",\\\"2013-05-17 20:00:00\\\",\\\"2013-05-18 02:00:00\\\",\\\"2013-05-18 08:00:00\\\",\\\"2013-05-18 14:00:00\\\",\\\"2013-05-18 20:00:00\\\",\\\"2013-05-19 02:00:00\\\",\\\"2013-05-19 08:00:00\\\",\\\"2013-05-19 14:00:00\\\",\\\"2013-05-19 20:00:00\\\",\\\"2013-05-20 02:00:00\\\",\\\"2013-05-20 08:00:00\\\",\\\"2013-05-20 14:00:00\\\",\\\"2013-05-20 20:00:00\\\",\\\"2013-05-21 02:00:00\\\",\\\"2013-05-21 08:00:00\\\",\\\"2013-05-21 14:00:00\\\",\\\"2013-05-21 20:00:00\\\",\\\"2013-05-22 02:00:00\\\",\\\"2013-05-22 08:00:00\\\",\\\"2013-05-22 14:00:00\\\",\\\"2013-05-22 20:00:00\\\",\\\"2013-05-23 02:00:00\\\",\\\"2013-05-23 08:00:00\\\",\\\"2013-05-23 14:00:00\\\",\\\"2013-05-23 20:00:00\\\",\\\"2013-05-24 02:00:00\\\",\\\"2013-05-24 08:00:00\\\",\\\"2013-05-24 14:00:00\\\",\\\"2013-05-24 20:00:00\\\",\\\"2013-05-25 02:00:00\\\",\\\"2013-05-25 08:00:00\\\",\\\"2013-05-25 14:00:00\\\",\\\"2013-05-25 20:00:00\\\",\\\"2013-05-26 02:00:00\\\",\\\"2013-05-26 08:00:00\\\",\\\"2013-05-26 14:00:00\\\",\\\"2013-05-26 20:00:00\\\",\\\"2013-05-27 02:00:00\\\",\\\"2013-05-27 08:00:00\\\",\\\"2013-05-27 14:00:00\\\",\\\"2013-05-27 20:00:00\\\",\\\"2013-05-28 02:00:00\\\",\\\"2013-05-28 08:00:00\\\",\\\"2013-05-28 14:00:00\\\",\\\"2013-05-28 20:00:00\\\",\\\"2013-05-29 02:00:00\\\",\\\"2013-05-29 08:00:00\\\",\\\"2013-05-29 14:00:00\\\",\\\"2013-05-29 20:00:00\\\",\\\"2013-05-30 02:00:00\\\",\\\"2013-05-30 08:00:00\\\",\\\"2013-05-30 14:00:00\\\",\\\"2013-05-30 20:00:00\\\",\\\"2013-05-31 02:00:00\\\",\\\"2013-05-31 08:00:00\\\",\\\"2013-05-31 14:00:00\\\",\\\"2013-05-31 20:00:00\\\",\\\"2013-06-01 02:00:00\\\",\\\"2013-06-01 08:00:00\\\",\\\"2013-06-01 14:00:00\\\",\\\"2013-06-01 20:00:00\\\",\\\"2013-06-02 02:00:00\\\",\\\"2013-06-02 08:00:00\\\",\\\"2013-06-02 14:00:00\\\",\\\"2013-06-02 20:00:00\\\",\\\"2013-06-03 02:00:00\\\",\\\"2013-06-03 08:00:00\\\",\\\"2013-06-03 14:00:00\\\",\\\"2013-06-03 20:00:00\\\",\\\"2013-06-04 02:00:00\\\",\\\"2013-06-04 08:00:00\\\",\\\"2013-06-04 14:00:00\\\",\\\"2013-06-04 20:00:00\\\",\\\"2013-06-05 02:00:00\\\",\\\"2013-06-05 08:00:00\\\",\\\"2013-06-05 14:00:00\\\",\\\"2013-06-05 20:00:00\\\",\\\"2013-06-06 02:00:00\\\",\\\"2013-06-06 08:00:00\\\",\\\"2013-06-06 14:00:00\\\",\\\"2013-06-06 20:00:00\\\",\\\"2013-06-07 02:00:00\\\",\\\"2013-06-07 08:00:00\\\",\\\"2013-06-07 14:00:00\\\",\\\"2013-06-07 20:00:00\\\",\\\"2013-06-08 02:00:00\\\",\\\"2013-06-08 08:00:00\\\",\\\"2013-06-08 14:00:00\\\",\\\"2013-06-08 20:00:00\\\",\\\"2013-06-09 02:00:00\\\",\\\"2013-06-09 08:00:00\\\",\\\"2013-06-09 14:00:00\\\",\\\"2013-06-09 20:00:00\\\",\\\"2013-06-10 02:00:00\\\",\\\"2013-06-10 08:00:00\\\",\\\"2013-06-10 14:00:00\\\",\\\"2013-06-10 20:00:00\\\",\\\"2013-06-11 02:00:00\\\",\\\"2013-06-11 08:00:00\\\",\\\"2013-06-11 14:00:00\\\",\\\"2013-06-11 20:00:00\\\",\\\"2013-06-12 02:00:00\\\",\\\"2013-06-12 08:00:00\\\",\\\"2013-06-12 14:00:00\\\",\\\"2013-06-12 20:00:00\\\",\\\"2013-06-13 02:00:00\\\",\\\"2013-06-13 08:00:00\\\",\\\"2013-06-13 14:00:00\\\",\\\"2013-06-13 20:00:00\\\",\\\"2013-06-14 02:00:00\\\",\\\"2013-06-14 08:00:00\\\",\\\"2013-06-14 14:00:00\\\",\\\"2013-06-14 20:00:00\\\",\\\"2013-06-15 02:00:00\\\",\\\"2013-06-15 08:00:00\\\",\\\"2013-06-15 14:00:00\\\",\\\"2013-06-15 20:00:00\\\",\\\"2013-06-16 02:00:00\\\",\\\"2013-06-16 08:00:00\\\",\\\"2013-06-16 14:00:00\\\",\\\"2013-06-16 20:00:00\\\",\\\"2013-06-17 02:00:00\\\",\\\"2013-06-17 08:00:00\\\",\\\"2013-06-17 14:00:00\\\",\\\"2013-06-17 20:00:00\\\",\\\"2013-06-18 02:00:00\\\",\\\"2013-06-18 08:00:00\\\",\\\"2013-06-18 14:00:00\\\",\\\"2013-06-18 20:00:00\\\",\\\"2013-06-19 02:00:00\\\",\\\"2013-06-19 08:00:00\\\",\\\"2013-06-19 14:00:00\\\",\\\"2013-06-19 20:00:00\\\",\\\"2013-06-20 02:00:00\\\",\\\"2013-06-20 08:00:00\\\",\\\"2013-06-20 14:00:00\\\",\\\"2013-06-20 20:00:00\\\",\\\"2013-06-21 02:00:00\\\",\\\"2013-06-21 08:00:00\\\",\\\"2013-06-21 14:00:00\\\",\\\"2013-06-21 20:00:00\\\",\\\"2013-06-22 02:00:00\\\",\\\"2013-06-22 08:00:00\\\",\\\"2013-06-22 14:00:00\\\",\\\"2013-06-22 20:00:00\\\",\\\"2013-06-23 02:00:00\\\",\\\"2013-06-23 08:00:00\\\",\\\"2013-06-23 14:00:00\\\",\\\"2013-06-23 20:00:00\\\",\\\"2013-06-24 02:00:00\\\",\\\"2013-06-24 08:00:00\\\",\\\"2013-06-24 14:00:00\\\",\\\"2013-06-24 20:00:00\\\",\\\"2013-06-25 02:00:00\\\",\\\"2013-06-25 08:00:00\\\",\\\"2013-06-25 14:00:00\\\",\\\"2013-06-25 20:00:00\\\",\\\"2013-06-26 02:00:00\\\",\\\"2013-06-26 08:00:00\\\",\\\"2013-06-26 14:00:00\\\",\\\"2013-06-26 20:00:00\\\",\\\"2013-06-27 02:00:00\\\",\\\"2013-06-27 08:00:00\\\",\\\"2013-06-27 14:00:00\\\",\\\"2013-06-27 20:00:00\\\",\\\"2013-06-28 02:00:00\\\",\\\"2013-06-28 08:00:00\\\",\\\"2013-06-28 14:00:00\\\",\\\"2013-06-28 20:00:00\\\",\\\"2013-06-29 02:00:00\\\",\\\"2013-06-29 08:00:00\\\",\\\"2013-06-29 14:00:00\\\",\\\"2013-06-29 20:00:00\\\",\\\"2013-06-30 02:00:00\\\",\\\"2013-06-30 08:00:00\\\",\\\"2013-06-30 14:00:00\\\",\\\"2013-06-30 20:00:00\\\",\\\"2013-07-01 02:00:00\\\",\\\"2013-07-01 08:00:00\\\",\\\"2013-07-01 14:00:00\\\",\\\"2013-07-01 20:00:00\\\",\\\"2013-07-02 02:00:00\\\",\\\"2013-07-02 08:00:00\\\",\\\"2013-07-02 14:00:00\\\",\\\"2013-07-02 20:00:00\\\",\\\"2013-07-03 02:00:00\\\",\\\"2013-07-03 08:00:00\\\",\\\"2013-07-03 14:00:00\\\",\\\"2013-07-03 20:00:00\\\",\\\"2013-07-04 02:00:00\\\",\\\"2013-07-04 08:00:00\\\",\\\"2013-07-04 14:00:00\\\",\\\"2013-07-04 20:00:00\\\",\\\"2013-07-05 02:00:00\\\",\\\"2013-07-05 08:00:00\\\",\\\"2013-07-05 14:00:00\\\",\\\"2013-07-05 20:00:00\\\",\\\"2013-07-06 02:00:00\\\",\\\"2013-07-06 08:00:00\\\",\\\"2013-07-06 14:00:00\\\",\\\"2013-07-06 20:00:00\\\",\\\"2013-07-07 02:00:00\\\",\\\"2013-07-07 08:00:00\\\",\\\"2013-07-07 14:00:00\\\",\\\"2013-07-07 20:00:00\\\",\\\"2013-07-08 02:00:00\\\",\\\"2013-07-08 08:00:00\\\",\\\"2013-07-08 14:00:00\\\",\\\"2013-07-08 20:00:00\\\",\\\"2013-07-09 02:00:00\\\",\\\"2013-07-09 08:00:00\\\",\\\"2013-07-09 14:00:00\\\",\\\"2013-07-09 20:00:00\\\",\\\"2013-07-10 02:00:00\\\",\\\"2013-07-10 08:00:00\\\",\\\"2013-07-10 14:00:00\\\",\\\"2013-07-10 20:00:00\\\",\\\"2013-07-11 02:00:00\\\",\\\"2013-07-11 08:00:00\\\",\\\"2013-07-11 14:00:00\\\",\\\"2013-07-11 20:00:00\\\",\\\"2013-07-12 02:00:00\\\",\\\"2013-07-12 08:00:00\\\",\\\"2013-07-12 14:00:00\\\",\\\"2013-07-12 20:00:00\\\",\\\"2013-07-13 02:00:00\\\",\\\"2013-07-13 08:00:00\\\",\\\"2013-07-13 14:00:00\\\",\\\"2013-07-13 20:00:00\\\",\\\"2013-07-14 02:00:00\\\",\\\"2013-07-14 08:00:00\\\",\\\"2013-07-14 14:00:00\\\",\\\"2013-07-14 20:00:00\\\",\\\"2013-07-15 02:00:00\\\",\\\"2013-07-15 08:00:00\\\",\\\"2013-07-15 14:00:00\\\",\\\"2013-07-15 20:00:00\\\",\\\"2013-07-16 02:00:00\\\",\\\"2013-07-16 08:00:00\\\",\\\"2013-07-16 14:00:00\\\",\\\"2013-07-16 20:00:00\\\",\\\"2013-07-17 02:00:00\\\",\\\"2013-07-17 08:00:00\\\",\\\"2013-07-17 14:00:00\\\",\\\"2013-07-17 20:00:00\\\",\\\"2013-07-18 02:00:00\\\",\\\"2013-07-18 08:00:00\\\",\\\"2013-07-18 14:00:00\\\",\\\"2013-07-18 20:00:00\\\",\\\"2013-07-19 02:00:00\\\",\\\"2013-07-19 08:00:00\\\",\\\"2013-07-19 14:00:00\\\",\\\"2013-07-19 20:00:00\\\",\\\"2013-07-20 02:00:00\\\",\\\"2013-07-20 08:00:00\\\",\\\"2013-07-20 14:00:00\\\",\\\"2013-07-20 20:00:00\\\",\\\"2013-07-21 02:00:00\\\",\\\"2013-07-21 08:00:00\\\",\\\"2013-07-21 14:00:00\\\",\\\"2013-07-21 20:00:00\\\",\\\"2013-07-22 02:00:00\\\",\\\"2013-07-22 08:00:00\\\",\\\"2013-07-22 14:00:00\\\",\\\"2013-07-22 20:00:00\\\",\\\"2013-07-23 02:00:00\\\",\\\"2013-07-23 08:00:00\\\",\\\"2013-07-23 14:00:00\\\",\\\"2013-07-23 20:00:00\\\",\\\"2013-07-24 02:00:00\\\",\\\"2013-07-24 08:00:00\\\",\\\"2013-07-24 14:00:00\\\",\\\"2013-07-24 20:00:00\\\",\\\"2013-07-25 02:00:00\\\",\\\"2013-07-25 08:00:00\\\",\\\"2013-07-25 14:00:00\\\",\\\"2013-07-25 20:00:00\\\",\\\"2013-07-26 02:00:00\\\",\\\"2013-07-26 08:00:00\\\",\\\"2013-07-26 14:00:00\\\",\\\"2013-07-26 20:00:00\\\",\\\"2013-07-27 02:00:00\\\",\\\"2013-07-27 08:00:00\\\",\\\"2013-07-27 14:00:00\\\",\\\"2013-07-27 20:00:00\\\",\\\"2013-07-28 02:00:00\\\",\\\"2013-07-28 08:00:00\\\",\\\"2013-07-28 14:00:00\\\",\\\"2013-07-28 20:00:00\\\",\\\"2013-07-29 02:00:00\\\",\\\"2013-07-29 08:00:00\\\",\\\"2013-07-29 14:00:00\\\",\\\"2013-07-29 20:00:00\\\",\\\"2013-07-30 02:00:00\\\",\\\"2013-07-30 08:00:00\\\",\\\"2013-07-30 14:00:00\\\",\\\"2013-07-30 20:00:00\\\",\\\"2013-07-31 02:00:00\\\",\\\"2013-07-31 08:00:00\\\",\\\"2013-07-31 14:00:00\\\",\\\"2013-07-31 20:00:00\\\",\\\"2013-08-01 02:00:00\\\",\\\"2013-08-01 08:00:00\\\",\\\"2013-08-01 14:00:00\\\",\\\"2013-08-01 20:00:00\\\",\\\"2013-08-02 02:00:00\\\",\\\"2013-08-02 08:00:00\\\",\\\"2013-08-02 14:00:00\\\",\\\"2013-08-02 20:00:00\\\",\\\"2013-08-03 02:00:00\\\",\\\"2013-08-03 08:00:00\\\",\\\"2013-08-03 14:00:00\\\",\\\"2013-08-03 20:00:00\\\",\\\"2013-08-04 02:00:00\\\",\\\"2013-08-04 08:00:00\\\",\\\"2013-08-04 14:00:00\\\",\\\"2013-08-04 20:00:00\\\",\\\"2013-08-05 02:00:00\\\",\\\"2013-08-05 08:00:00\\\",\\\"2013-08-05 14:00:00\\\",\\\"2013-08-05 20:00:00\\\",\\\"2013-08-06 02:00:00\\\",\\\"2013-08-06 08:00:00\\\",\\\"2013-08-06 14:00:00\\\",\\\"2013-08-06 20:00:00\\\",\\\"2013-08-07 02:00:00\\\",\\\"2013-08-07 08:00:00\\\",\\\"2013-08-07 14:00:00\\\",\\\"2013-08-07 20:00:00\\\",\\\"2013-08-08 02:00:00\\\",\\\"2013-08-08 08:00:00\\\",\\\"2013-08-08 14:00:00\\\",\\\"2013-08-08 20:00:00\\\",\\\"2013-08-09 02:00:00\\\",\\\"2013-08-09 08:00:00\\\",\\\"2013-08-09 14:00:00\\\",\\\"2013-08-09 20:00:00\\\",\\\"2013-08-10 02:00:00\\\",\\\"2013-08-10 08:00:00\\\",\\\"2013-08-10 14:00:00\\\",\\\"2013-08-10 20:00:00\\\",\\\"2013-08-11 02:00:00\\\",\\\"2013-08-11 08:00:00\\\",\\\"2013-08-11 14:00:00\\\",\\\"2013-08-11 20:00:00\\\",\\\"2013-08-12 02:00:00\\\",\\\"2013-08-12 08:00:00\\\",\\\"2013-08-12 14:00:00\\\",\\\"2013-08-12 20:00:00\\\",\\\"2013-08-13 02:00:00\\\",\\\"2013-08-13 08:00:00\\\",\\\"2013-08-13 14:00:00\\\",\\\"2013-08-13 20:00:00\\\",\\\"2013-08-14 02:00:00\\\",\\\"2013-08-14 08:00:00\\\",\\\"2013-08-14 14:00:00\\\",\\\"2013-08-14 20:00:00\\\",\\\"2013-08-15 02:00:00\\\",\\\"2013-08-15 08:00:00\\\",\\\"2013-08-15 14:00:00\\\",\\\"2013-08-15 20:00:00\\\",\\\"2013-08-16 02:00:00\\\",\\\"2013-08-16 08:00:00\\\",\\\"2013-08-16 14:00:00\\\",\\\"2013-08-16 20:00:00\\\",\\\"2013-08-17 02:00:00\\\",\\\"2013-08-17 08:00:00\\\",\\\"2013-08-17 14:00:00\\\",\\\"2013-08-17 20:00:00\\\",\\\"2013-08-18 02:00:00\\\",\\\"2013-08-18 08:00:00\\\",\\\"2013-08-18 14:00:00\\\",\\\"2013-08-18 20:00:00\\\",\\\"2013-08-19 02:00:00\\\",\\\"2013-08-19 08:00:00\\\",\\\"2013-08-19 14:00:00\\\",\\\"2013-08-19 20:00:00\\\",\\\"2013-08-20 02:00:00\\\",\\\"2013-08-20 08:00:00\\\",\\\"2013-08-20 14:00:00\\\",\\\"2013-08-20 20:00:00\\\",\\\"2013-08-21 02:00:00\\\",\\\"2013-08-21 08:00:00\\\",\\\"2013-08-21 14:00:00\\\",\\\"2013-08-21 20:00:00\\\",\\\"2013-08-22 02:00:00\\\",\\\"2013-08-22 08:00:00\\\",\\\"2013-08-22 14:00:00\\\",\\\"2013-08-22 20:00:00\\\",\\\"2013-08-23 02:00:00\\\",\\\"2013-08-23 08:00:00\\\",\\\"2013-08-23 14:00:00\\\",\\\"2013-08-23 20:00:00\\\",\\\"2013-08-24 02:00:00\\\",\\\"2013-08-24 08:00:00\\\",\\\"2013-08-24 14:00:00\\\",\\\"2013-08-24 20:00:00\\\",\\\"2013-08-25 02:00:00\\\",\\\"2013-08-25 08:00:00\\\",\\\"2013-08-25 14:00:00\\\",\\\"2013-08-25 20:00:00\\\",\\\"2013-08-26 02:00:00\\\",\\\"2013-08-26 08:00:00\\\",\\\"2013-08-26 14:00:00\\\",\\\"2013-08-26 20:00:00\\\",\\\"2013-08-27 02:00:00\\\",\\\"2013-08-27 08:00:00\\\",\\\"2013-08-27 14:00:00\\\",\\\"2013-08-27 20:00:00\\\",\\\"2013-08-28 02:00:00\\\",\\\"2013-08-28 08:00:00\\\",\\\"2013-08-28 14:00:00\\\",\\\"2013-08-28 20:00:00\\\",\\\"2013-08-29 02:00:00\\\",\\\"2013-08-29 08:00:00\\\",\\\"2013-08-29 14:00:00\\\",\\\"2013-08-29 20:00:00\\\",\\\"2013-08-30 02:00:00\\\",\\\"2013-08-30 08:00:00\\\",\\\"2013-08-30 14:00:00\\\",\\\"2013-08-30 20:00:00\\\",\\\"2013-08-31 02:00:00\\\",\\\"2013-08-31 08:00:00\\\",\\\"2013-08-31 14:00:00\\\",\\\"2013-08-31 20:00:00\\\",\\\"2013-09-01 02:00:00\\\",\\\"2013-09-01 08:00:00\\\",\\\"2013-09-01 14:00:00\\\",\\\"2013-09-01 20:00:00\\\",\\\"2013-09-02 02:00:00\\\",\\\"2013-09-02 08:00:00\\\",\\\"2013-09-02 14:00:00\\\",\\\"2013-09-02 20:00:00\\\",\\\"2013-09-03 02:00:00\\\",\\\"2013-09-03 08:00:00\\\",\\\"2013-09-03 14:00:00\\\",\\\"2013-09-03 20:00:00\\\",\\\"2013-09-04 02:00:00\\\",\\\"2013-09-04 08:00:00\\\",\\\"2013-09-04 14:00:00\\\",\\\"2013-09-04 20:00:00\\\",\\\"2013-09-05 02:00:00\\\",\\\"2013-09-05 08:00:00\\\",\\\"2013-09-05 14:00:00\\\",\\\"2013-09-05 20:00:00\\\",\\\"2013-09-06 02:00:00\\\",\\\"2013-09-06 08:00:00\\\",\\\"2013-09-06 14:00:00\\\",\\\"2013-09-06 20:00:00\\\",\\\"2013-09-07 02:00:00\\\",\\\"2013-09-07 08:00:00\\\",\\\"2013-09-07 14:00:00\\\",\\\"2013-09-07 20:00:00\\\",\\\"2013-09-08 02:00:00\\\",\\\"2013-09-08 08:00:00\\\",\\\"2013-09-08 14:00:00\\\",\\\"2013-09-08 20:00:00\\\",\\\"2013-09-09 02:00:00\\\",\\\"2013-09-09 08:00:00\\\",\\\"2013-09-09 14:00:00\\\",\\\"2013-09-09 20:00:00\\\",\\\"2013-09-10 02:00:00\\\",\\\"2013-09-10 08:00:00\\\",\\\"2013-09-10 14:00:00\\\",\\\"2013-09-10 20:00:00\\\",\\\"2013-09-11 02:00:00\\\",\\\"2013-09-11 08:00:00\\\",\\\"2013-09-11 14:00:00\\\",\\\"2013-09-11 20:00:00\\\",\\\"2013-09-12 02:00:00\\\",\\\"2013-09-12 08:00:00\\\",\\\"2013-09-12 14:00:00\\\",\\\"2013-09-12 20:00:00\\\",\\\"2013-09-13 02:00:00\\\",\\\"2013-09-13 08:00:00\\\",\\\"2013-09-13 14:00:00\\\",\\\"2013-09-13 20:00:00\\\",\\\"2013-09-14 02:00:00\\\",\\\"2013-09-14 08:00:00\\\",\\\"2013-09-14 14:00:00\\\",\\\"2013-09-14 20:00:00\\\",\\\"2013-09-15 02:00:00\\\",\\\"2013-09-15 08:00:00\\\",\\\"2013-09-15 14:00:00\\\",\\\"2013-09-15 20:00:00\\\",\\\"2013-09-16 02:00:00\\\",\\\"2013-09-16 08:00:00\\\",\\\"2013-09-16 14:00:00\\\",\\\"2013-09-16 20:00:00\\\",\\\"2013-09-17 02:00:00\\\",\\\"2013-09-17 08:00:00\\\",\\\"2013-09-17 14:00:00\\\",\\\"2013-09-17 20:00:00\\\",\\\"2013-09-18 02:00:00\\\",\\\"2013-09-18 08:00:00\\\",\\\"2013-09-18 14:00:00\\\",\\\"2013-09-18 20:00:00\\\",\\\"2013-09-19 02:00:00\\\",\\\"2013-09-19 08:00:00\\\",\\\"2013-09-19 14:00:00\\\",\\\"2013-09-19 20:00:00\\\",\\\"2013-09-20 02:00:00\\\",\\\"2013-09-20 08:00:00\\\",\\\"2013-09-20 14:00:00\\\",\\\"2013-09-20 20:00:00\\\",\\\"2013-09-21 02:00:00\\\",\\\"2013-09-21 08:00:00\\\",\\\"2013-09-21 14:00:00\\\",\\\"2013-09-21 20:00:00\\\",\\\"2013-09-22 02:00:00\\\",\\\"2013-09-22 08:00:00\\\",\\\"2013-09-22 14:00:00\\\",\\\"2013-09-22 20:00:00\\\",\\\"2013-09-23 02:00:00\\\",\\\"2013-09-23 08:00:00\\\",\\\"2013-09-23 14:00:00\\\",\\\"2013-09-23 20:00:00\\\",\\\"2013-09-24 02:00:00\\\",\\\"2013-09-24 08:00:00\\\",\\\"2013-09-24 14:00:00\\\",\\\"2013-09-24 20:00:00\\\",\\\"2013-09-25 02:00:00\\\",\\\"2013-09-25 08:00:00\\\",\\\"2013-09-25 14:00:00\\\",\\\"2013-09-25 20:00:00\\\",\\\"2013-09-26 02:00:00\\\",\\\"2013-09-26 08:00:00\\\",\\\"2013-09-26 14:00:00\\\",\\\"2013-09-26 20:00:00\\\",\\\"2013-09-27 02:00:00\\\",\\\"2013-09-27 08:00:00\\\",\\\"2013-09-27 14:00:00\\\",\\\"2013-09-27 20:00:00\\\",\\\"2013-09-28 02:00:00\\\",\\\"2013-09-28 08:00:00\\\",\\\"2013-09-28 14:00:00\\\",\\\"2013-09-28 20:00:00\\\",\\\"2013-09-29 02:00:00\\\",\\\"2013-09-29 08:00:00\\\",\\\"2013-09-29 14:00:00\\\",\\\"2013-09-29 20:00:00\\\",\\\"2013-09-30 02:00:00\\\",\\\"2013-09-30 08:00:00\\\"]\",\"rain\":\"[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.272727,0.0,0.0,0.0,0.0,0.090909,8.18181,3.727269,0.363636,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.636363,0.90909,0.0,0.090909,0.0,9.454536000000001,4.363632,0.0,1.8181800000000001,5.181813,0.181818,0.0,0.0,0.0,0.0,0.181818,0.727272,0.0,0.0,2.272725,2.999997,0.454545,0.9999990000000001,1.090908,0.9090900000000001,0.0,0.0,0.0,2.6363610000000004,0.0,0.181818,0.090909,4.272723,0.545454,2.6363609999999995,0.181818,0.363636,0.0,0.0,0.0,1.454544,0.0,0.0,0.181818,0.727272,0.0,0.0,0.727272,1.454544,1.090908,0.0,1.81818,1.454544,0.090909,0.0,1.272726,1.090908,0.0,0.0,0.090909,0.818181,0.0,0.0,0.181818,0.45454500000000003,0.0,0.181818,0.0,0.636363,0.0,0.0,0.090909,0.0,0.0,0.0,0.090909,4.181814,2.545452,7.090902,3.727269,1.81818,0.636363,4.727268,8.818173000000002,3.8818142909091,0.6727266181818001,0.5363631000000001,0.0,0.0,0.090909,5.999993999999999,3.4545419999999996,3.3636329999999997,0.9090900000000001,0.272727,0.363636,2.909088,1.727271,0.999999,0.090909,0.363636,0.272727,0.090909,0.545454,1.6363619999999999,0.181818,0.0,0.181818,0.454545,0.0,0.181818,0.272727,0.363636,0.0,0.0,0.0,0.0,0.0,0.363636,0.090909,0.818181,0.9090900000000001,0.0,0.090909,0.0,0.0,0.0,0.272727,1.090908,0.0,0.0,0.090909,0.272727,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.9090890000000003,0.0,0.090909,0.090909,0.090909,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,3.545451,21.81816,7.454537999999999,1.1818170000000001,0.181818,0.0,0.0,0.0,0.0,0.0,0.0,0.0,8.454537,2.545452,0.272727,0.0,0.0,0.090909,1.090908,0.090909,0.0,0.0,0.0,0.0,0.0,2.636361,0.0,0.0,2.636361,5.636358,1.9999979999999997,0.090909,0.45454500000000003,9.545445,0.727272,0.090909,0.818181,1.9090889999999998,0.090909,0.0,0.0,0.0,0.363636,0.0,0.0,0.0,0.0,0.0,20.090889,8.818173,2.72727,0.181818,0.090909,0.0,0.0,1.454544,0.636363,7.727265,0.181818,0.090909,0.0,0.545454,3.272724,10.999989000000001,0.181818,0.090909,0.0,14.090895000000002,5.0181767818182,0.21818160000000003,8.454537,0.7636356,0.0,4.363632,4.727268,0.0,0.181818,1.545453,0.181818,0.0,0.181818,5.181813,0.090909,0.181818,3.454542,1.545453,0.0,0.0,0.0,2.4545429999999997,1.363635,0.0,0.0,0.0,0.0,0.181818,0.363636,0.45454500000000003,0.181818,0.45454500000000003,0.727272,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.818181,9.727263,0.090909,0.090909,4.7272680000000005,1.1818170000000001,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.545454,4.545450000000001,0.727272,6.909084000000001,1.272726,2.545452,0.0,0.181818,0.0,0.090909,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.363635,9.545445,6.545448,2.3090886,0.2181816,0.10909081818180001,0.545454,0.090909,0.0,0.0,0.0,0.363636,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.1818170000000001,0.363636,0.090909,0.0,0.181818,0.636363,0.090909,0.0,0.0,0.0,0.727272,8.090901,6.272721000000001,6.636357,2.3636339818182,0.0,0.0,0.0,0.0,0.0,0.363636,0.090909,0.0,0.090909,0.636363,0.545454,0.090909,0.0,1.090908,0.090909,0.0,0.272727,0.272727,0.0,0.0,0.090909,0.090909,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.090909,1.090908,1.363635,0.636363,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,6.727266000000001,0.9090900000000001,0.090909,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,3.2727239999999997,0.272727,0.090909,0.0,2.6363609999999995,3.9090869999999995,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.090909,11.727261,8.727263999999998,0.272727,0.090909,0.090909,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.363636,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]\",\"q\":\"[]\",\"SE\":\"[0.1, 0.5, 0.9]\",\"runoffSim\":\"[]\",\"IA\":\"[[-9999.0,-9999.0,-9999.0],[36.8,19.6,4.0],[19.8,10.2,1.8],[11.5,5.5,0.8],[8.3,3.8,0.5],[7.2,3.3,0.5]]\",\"start\":\"\\\"2013-06-01 08:00:00\\\"\",\"I\":\"[0.001, 0.002, 0.3, 0.5, 0.8, 1]\",\"clen\":\"6\",\"SE0\":\"0.3\",\"FE\":\"[[-9999.0,-9999.0,-9999.0],[0.17,0.17,0.17],[0.17,0.17,0.17],[0.17,0.17,0.17],[0.17,0.17,0.17],[0.17,0.17,0.17]]\"}";
        Map data = JSON.parseObject(a, Map.class);
        ITCA obj = new ITCA(data);
        System.out.println(obj.predict());
    }
}
